package com.xiyuan.almighty.service;

import java.util.concurrent.TimeUnit;

import java.awt.*;

/**
 * @创建人 袁继鑫
 * @创建时间 2021-03-31 14:18
 * @版本 1.0
 * @描述
 */
public class TestThread {
    public static void main(String[] args) throws InterruptedException {
        LiftOff liftOff = new LiftOff();
        Thread thread = new Thread(liftOff);
        thread.getState();
        thread.start();
        System.out.println("Waiting for LiftOff");
        TimeUnit.MILLISECONDS.sleep(100);
        Thread thread1 = new Thread(liftOff);
        thread1.start();

    }
}

class Sleeper extends Thread {
    private int duration;

    public Sleeper(String name, int sleepTime) {
        super(name);
        duration = sleepTime;
        start();
    }

}


class LiftOff implements Runnable {
    protected int countDown = 10;
    private static int taskCount = 0;
    private final int id = taskCount++;

    public LiftOff() {
    }

    public LiftOff(int countDown) {
        this.countDown = countDown;
    }

    public String status() {
        return "#" + id + "(" + (countDown > 0 ? countDown : "Liftoff !") + ")";
    }

    @Override
    public void run() {
        while (countDown-- > 0) {
            System.out.println(status());
            Thread.yield();
        }
    }
}
